import xadmin
from xadmin import views

from . import models

class BaseSetting(object):
    """xadmin的基本配置"""
    enable_themes = True  # 开启主题切换功能
    use_bootswatch = True

xadmin.site.register(views.BaseAdminView, BaseSetting)

class GlobalSettings(object):
    """xadmin的全局配置"""
    site_title = "美多商城运营管理系统"  # 设置站点标题
    site_footer = "美多商城集团有限公司"  # 设置站点的页脚
    menu_style = "accordion"  # 设置菜单折叠

xadmin.site.register(views.CommAdminView, GlobalSettings)


#美多商城的模型类
class SKUAdmin(object):
    #1,显示左侧图片
    # model_icon = 'fa fa-gift'
    model_icon = 'fa fa-camera-retro'

    #2,显示展示的字段
    list_display = ['id', 'name', 'price', 'stock', 'sales', 'comments']

    #3,搜索字段
    search_fields = ['id', 'name']

    #4,过滤
    list_filter = ['category']

    #5,局部更新
    list_editable = ['price', 'stock']

    #6,显示详情
    show_detail_fields = ['name']

    #7,指定数据导出格式
    list_export = ['xls', 'csv', 'xml']

    #8,更新时间
    refresh_times = [3, 5]  # 可选以支持按多长时间(秒)刷新页面

    pass

xadmin.site.register(models.SKU, SKUAdmin)